package cn.fairy.service.impl;

import cn.fairy.domian.Product;
import cn.fairy.domian.Store;
import cn.fairy.dto.ProductDto;
import cn.fairy.fegin.ProductClient;
import cn.fairy.mapper.ProductMapper;
import cn.fairy.service.IProductService;
import cn.fairy.utils.AjaxResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements IProductService {
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private ProductClient productClient;


    @Override
    public void add(ProductDto productDto) {
        Product product = new Product();
        BeanUtils.copyProperties(productDto,product);
        productMapper.add(product);
        Store store = new Store();
        store.setProduct_id(product.getId())
                        .setNumber(productDto.getNumber());
        AjaxResult result = productClient.add(store);
        if(!result.getSuccess()){
            throw new RuntimeException();
        }
    }
}
